Skip to content

Make quarto_render(as_job = TRUE) wrapable#105

Merged
cderv merged 20 commits into
quarto-dev:mainfrom
salim-b:improve-render
Jun 10, 2025
Merged

Make quarto_render(as_job = TRUE) wrapable#105
cderv merged 20 commits into
quarto-dev:mainfrom
salim-b:improve-render

Conversation

@salim-b

@salim-b salim-b commented May 9, 2023

Copy link
Copy Markdown
Contributor

Currently, quarto_render() cannot be wrapped in another function and run as a background job (as_job = TRUE) at the same time because of a naive deparse(Sys.call()) usage.

This PR properly evaluates and then deparses all provided arguments, so arguments are actually forwarded to quarto_render() when called inside another function. Before this PR, the following code would fail with error object 'path' not found:

dir <- rprojroot::find_testthat_root_file()
input <- file.path(dir, "test.Rmd")
output <- file.path(dir, "test.html")
wrapper <- function(path) quarto_render(path, quiet = TRUE, as_job = TRUE)
wrapper(input)

Addendum: rstudio/rstudio#12764 does not make this PR obsolete.

@cderv cderv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I understand the problem.

That looks good but I wonder if it would be a bit better to try use rlang to handle the construction of the call, especially for '...' handling

This could require the change regarding missing() usage to make this works correctly.

I'll probably merge like this to unblock, and deal with that later

Comment thread R/render.R
Comment on lines +89 to +98
render_args <- as.list(sys.call()[-1L])
render_args <- mapply(
function(arg, arg_name) paste0(
arg_name,
"="[nchar(arg_name) > 0L],
deparse1(eval(arg, envir = parent.frame(n = 3L)))
),
render_args,
names(render_args)
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to handle this a bit differently for complex wrapping calls that would use ... for example. In this case, it will not work. rlang maybe be useful for this. 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, I didn't test with a wrapper function that uses dots, I only tested simple named args. Feel free to refactor and expand on this PR as you see fit!

@cderv

cderv commented Mar 7, 2024

Copy link
Copy Markdown
Member

Thanks for updating. I postponed this for a later version, but still plan to come again into it. Thanks for the wait.

@cderv
cderv merged commit 8a0d1ee into quarto-dev:main Jun 10, 2025
16 checks passed
@salim-b
salim-b deleted the improve-render branch June 10, 2025 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants